package com.example.clientbwic.utils;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 86150
 * @Date: 2024/4/13
 * @Description: com.example.clientbwic.utils
 */

/**
 * @author CCL
 * @since 2021年12月24日
 */
@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;
    /**
     * 成功,只能是0
     */
    private static final int SUCCESS_CODE = 0;
    public static final String SUCCESS_MESSAGE = "操作成功";
    /**
     * 登录失败
     */
    public static final int LOGIN_FAIL_CODE = -101;
    public static final String FAIL_MESSAGE = "操作失败";


    public static <T> Result<T> success(T data) {
        return new Result<>(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(SUCCESS_CODE, message, data);
    }

    public static <T> Result<T> fail() {
        return new Result<>(LOGIN_FAIL_CODE, FAIL_MESSAGE, null);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(LOGIN_FAIL_CODE, message, null);
    }

    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(code, message, null);
    }

    private Result(int code, String message, T data) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }

}


